<body>
    <input id='k1'>
    <select id='op'>
        <option value='+'>+</option>
        <option value='-'>-</option>
        <option value='*'>*</option>
    </select>
    <input id='k2'>
    <button id='eq'>=</button>
    <span id='v1'></span>

    <hr />
    <input id='v15' value='10485760000000G' /> <span id='v'></span> <span id='s15'></span> <span id='s16'></span>

    <hr />
    <pre>

    </pre>
</body>
<script src='./jquery.min.js' type='text/javascript'></script>
<script src="./unitNumber.js" type='text/javascript'></script>
<script src="./floatObj.js" type='text/javascript'></script>
<script>
    $(function () {

        function thousands(num) {
            var decimalPart = '';
            num = num.toString();
            if (num.indexOf('.') != -1) {
                decimalPart = '.' + num.split('.')[1];
                num = parseInt(num.split('.')[0]);
            }
            var array = num.toString().split('');
            var index = -3;
            while (array.length + index > 0) {
                array.splice(index, 0, ',');
                index -= 4;
            }
            return array.join('') + decimalPart;
        };

        function show(v) {
            var echo = unitNumber.echo(v);
            var system = unitNumber.norm(v);
            var sh = {
                echo: thousands(echo.n) + echo.u,
                system: thousands(system.n) + system.u
            };
            $('pre').html(JSON.stringify(sh, null, '\t'));
        }

        var v = 40 * 1024 * 1024 * 1024;
        $('#v11').val(v);
        $('#v12').val(v >> 10); //k
        $('#v13').val(v >> 20); //m
        $('#v14').val(v >> 30); //g

        $('#v15').on('input', function () {
            var v;
            try {
                v = eval($('#v15').val());
            } catch (err) {
                return;
            }
            $('#v').html(thousands(v));
            show(v);
        });

        $('#eq').click(function () {

            var k1 = $('#k1').val();
            var k2 = $('#k2').val();

            var op = $('#op').val();
            if (op === '+') {
                show(unitNumber.add(k1, k2));
            } else if (op === '-') {
                show(unitNumber.sub(k1, k2));
            } else if (op === '*') {
                show(unitNumber.mul(k1, k2));
            }
        })
    });
</script>